tooltipwindow: Use a builder UI file
authorEmmanuele Bassi <ebassi@gnome.org>
Wed, 11 Nov 2015 12:27:07 +0000 (12:27 +0000)
committerEmmanuele Bassi <ebassi@gnome.org>
Wed, 11 Nov 2015 12:27:07 +0000 (12:27 +0000)
It's not a hugely complicated file, but it's easier to deal with some of
the details of tooltip windows styling if we have a UI file to edit,
instead of source code.

gtk/Makefile.am
gtk/gtktooltipwindow.c
gtk/ui/gtktooltipwindow.ui [new file with mode: 0644]

index fd49c1403484a1ae516adae55cd0dbf8d55f7ff2..3c57ca5466673f392d8e2d4f0f02641312010284 100644 (file)
@@ -1126,6 +1126,7 @@ templates =                               \
        ui/gtksearchbar.ui              \
        ui/gtkscalebutton.ui            \
        ui/gtkstatusbar.ui              \
+       ui/gtktooltipwindow.ui          \
        ui/gtkvolumebutton.ui           \
        ui/gtksidebarrow.ui
 
index cb7cb53fc9a21a4bf3865188dba078887ab77a1c..4c9d51715a689610e2d45ed9ffc5be76c7eb4e8b 100644 (file)
@@ -65,6 +65,11 @@ gtk_tooltip_window_class_init (GtkTooltipWindowClass *klass)
 
   gtk_widget_class_set_css_name (widget_class, I_("tooltip"));
   gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_TIP);
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtktooltipwindow.ui");
+
+  gtk_widget_class_bind_template_child (widget_class, GtkTooltipWindow, box);
+  gtk_widget_class_bind_template_child (widget_class, GtkTooltipWindow, image);
+  gtk_widget_class_bind_template_child (widget_class, GtkTooltipWindow, label);
 }
 
 static void
@@ -72,28 +77,10 @@ gtk_tooltip_window_init (GtkTooltipWindow *self)
 {
   GtkWindow *window = GTK_WINDOW (self);
 
-  gtk_window_set_type_hint (window, GDK_WINDOW_TYPE_HINT_TOOLTIP);
-  gtk_window_set_resizable (window, FALSE);
-  gtk_window_set_use_subsurface (window, TRUE);
+  gtk_widget_init_template (GTK_WIDGET (self));
 
+  gtk_window_set_use_subsurface (window, TRUE);
   _gtk_window_request_csd (window);
-
-  /* FIXME: don't hardcode the padding */
-  self->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-  gtk_widget_set_margin_start (self->box, 6);
-  gtk_widget_set_margin_end (self->box, 6);
-  gtk_widget_set_margin_top (self->box, 6);
-  gtk_widget_set_margin_bottom (self->box, 6);
-  gtk_container_add (GTK_CONTAINER (self), self->box);
-  gtk_widget_show (self->box);
-
-  self->image = gtk_image_new ();
-  gtk_box_pack_start (GTK_BOX (self->box), self->image, FALSE, FALSE, 0);
-
-  self->label = gtk_label_new ("");
-  gtk_label_set_line_wrap (GTK_LABEL (self->label), TRUE);
-  gtk_label_set_max_width_chars (GTK_LABEL (self->label), MAX_TOOLTIP_LINE_WIDTH);
-  gtk_box_pack_start (GTK_BOX (self->box), self->label, FALSE, FALSE, 0);
 }
 
 GtkWidget *
diff --git a/gtk/ui/gtktooltipwindow.ui b/gtk/ui/gtktooltipwindow.ui
new file mode 100644 (file)
index 0000000..1cb2de0
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GtkTooltipWindow" parent="GtkWindow">
+    <property name="resizable">0</property>
+    <property name="type_hint">tooltip</property>
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="orientation">horizontal</property>
+        <property name="visible">1</property>
+        <property name="spacing">6</property>
+        <property name="margin_top">6</property>
+        <property name="margin_bottom">6</property>
+        <property name="margin_start">6</property>
+        <property name="margin_end">6</property>
+        <child>
+          <object class="GtkImage" id="image">
+            <property name="visible">0</property>
+            <property name="icon_name">image-missing</property>
+          </object>
+          <packing>
+            <property name="fill">0</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label">
+            <property name="visible">0</property>
+            <property name="wrap">1</property>
+            <property name="max_width_chars">70</property>
+            <property name="label"></property>
+          </object>
+          <packing>
+            <property name="fill">0</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>